package byteDemo;

import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        String byteStr = "1100011000";
        BigInteger bigInteger = new BigInteger(byteStr,2);
        BigInteger bigInteger1 = new BigInteger("100",2);
        bigInteger.and(bigInteger);

        //System.out.println(bigInteger.toString(2));
        byte l = 1;

        char status = byteStr.charAt(1);
        char status1 = byteStr.charAt(2);

        //System.out.println(status == '1');
        //System.out.println(status1 ==  '0');

        /*Integer status = 1<<2;
        Integer statusLen = Integer.toBinaryString(status).length();
        Integer byteStrLen = byteStr.length();
        if(byteStrLen < statusLen){
            String low = byteStr.substring(byteStrLen - statusLen -2);
            System.out.println(low);

        }*/

//        System.out.println(Integer.toBinaryString(1<<2).length());
//        System.out.println(Integer.toBinaryString(1<<3).length());
//        System.out.println(Integer.toBinaryString(1<<4).length());
//        System.out.println(Integer.toBinaryString(1<<5).length());
//        System.out.println(byteStr.substring(byteStr.length() - 2 -1));


        String status2 = "101010";
        System.out.println(alreadyTransfer(status2,7));
        System.out.println(alreadyTransfer(status2,0));
        System.out.println(alreadyTransfer(status2,1));
        System.out.println(alreadyTransfer(status2,3));
    }

    public static int getRightNum(byte b,int length) {
        byte mv=(byte) (0xff>>(8-length));
        return b&mv;
    }

    private static String genStatusStr(int statusIndex){
        return "1" + ZERO.substring(0,statusIndex);
    }

    private static final String ZERO;
    static {
        String temp = "";
        for (int i = 0; i < 125; i++) {
            temp += "0";
        }
        ZERO = temp;
    }


    public static String genFinalStatus(String currStatus, int statusIndex) {
        String waitAppendStatus = "1" + ZERO.substring(0, statusIndex);
        int waitAppendStatusLen = statusIndex + 1;
        if (currStatus != null && !currStatus.isEmpty()) {
            int currStatusLen = currStatus.length();
            if (currStatusLen == waitAppendStatusLen) {
                return "1" + currStatus.substring(1);
            } else if (currStatusLen < waitAppendStatusLen) {
                return waitAppendStatus.substring(0, waitAppendStatusLen - currStatusLen) + currStatus;
            } else {
                char[] statusArray = currStatus.toCharArray();
                statusArray[statusArray.length - waitAppendStatusLen] = '1';
                return new String(statusArray);
            }
        } else {
            return waitAppendStatus;
        }
    }

    public static boolean alreadyTransfer(String currStatus, int statusIndex) {
        if (currStatus != null && !currStatus.isEmpty()) {
            int currStatusLen = currStatus.length();
            if (currStatusLen > statusIndex) {
                char status = currStatus.charAt(currStatusLen - statusIndex - 1);
                if (status == '1') return true;
            }
        }
        return false;
    }
}
